<template>
  <nav-bar id="nav_bar"  ref="nav_bar"/>
  <h1>操作日志</h1>
  <el-table id="data_table"
            :data="table_data"
            stripe
            border
            style="width: 60%; margin: auto">
    <el-table-column prop="time" label="时间" sortable/>
    <el-table-column prop="username" label="用户名"/>
    <el-table-column prop="type" label="操作类型"/>
    <el-table-column prop="object" label="操作对象"/>
    <el-table-column prop="content" label="操作内容"/>
  </el-table>
</template>

<script>
import NavBar from "../components/nav-bar/nav_bar"
import axios from "axios";

export default {
  name: "OperationLog",
  components: {
    NavBar,
  },
  data() {
    return {
      table_data: [],
    }
  },
  methods: {
    reload_table_data() {
      axios.post(this.$store.state.post_site_dir.operation_log,
          {
            key: this.$store.state.key
          })
          .then((res) => {
            if (res.data.error_code !== 0) {
              this.$message.error('获取记录失败，请重新登录重试')
            } else {
              this.table_data = res.data.data
            }
          })
    }
  },
  mounted() {
    this.reload_table_data()
    // 设置导航栏的高亮
    this.$refs.nav_bar.set_default_active_nav(
        this.$store.state.object_code_dir.type2object_code.日志)
  }

}
</script>

<style scoped>

#nav_bar {
  top: 0;
  width: 100%;
  opacity: 1;
  z-index: 90;
}
#data_table {
  top: 20px;
  z-index: 50;
}
</style>